<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="报告期间" prop="reportingPeriod">
        <el-input
          v-model="queryParams.reportingPeriod"
          placeholder="请输入报告期间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原作品名" prop="originalTitle">
        <el-input
          v-model="queryParams.originalTitle"
          placeholder="请输入原作品名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="作品翻译书名" prop="titleEng">
        <el-input
          v-model="queryParams.titleEng"
          placeholder="请输入作品翻译书名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="权利人名" prop="obligeeName">
        <el-input
          v-model="queryParams.obligeeName"
          placeholder="请输入权利人名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理店名" prop="agentName">
        <el-input
          v-model="queryParams.agentName"
          placeholder="请输入代理店名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:form:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:form:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:form:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:form:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      border
      stripe
      v-loading="loading"
      :data="formList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="报告期间" align="center" prop="reportingPeriod" />
      <el-table-column label="卷数" align="center" prop="volume" />
      <el-table-column label="原作品名" align="center" prop="originalTitle" />
      <el-table-column label="作品翻译书名" align="center" prop="titleEng" />
      <el-table-column label="权利人名" align="center" prop="obligeeName" />
      <el-table-column label="代理店名" align="center" prop="agentName" />
      <el-table-column
        label="翻译出版日"
        align="center"
        prop="translationDay"
      />
      <el-table-column
        label="合同开始日"
        align="center"
        prop="commencementDate"
      />
      <el-table-column label="合同结束日" align="center" prop="terminateDate" />
      <el-table-column label="本期印刷数量" align="center" prop="printAmount" />
      <el-table-column label="本期销售数量" align="center" prop="salesAmount" />
      <el-table-column
        label="本期坏书·增书数量"
        align="center"
        prop="lossAmount"
      />
      <el-table-column label="本期末库存" align="center" prop="inventory" />
      <el-table-column
        label="本期末累计印刷数量"
        align="center"
        prop="totalPrintAmount"
      />
      <el-table-column
        label="本期末累计销售数量"
        align="center"
        prop="totalSalesAmount"
      />
      <el-table-column
        label="本期末累计坏书·增书数量"
        align="center"
        prop="totalLossAmount"
      />
      <el-table-column label="货币单位" align="center" prop="monetaryUnitOne" />
      <el-table-column label="定价" align="center" prop="pricing" />
      <el-table-column
        label="本期版税计算数量"
        align="center"
        prop="royaltyQuantity"
      />
      <el-table-column label="货币单位" align="center" prop="monetaryUnitTwo" />
      <el-table-column
        label="本期销售/印刷金额"
        align="center"
        prop="salesAmountPrintAmount"
      />
      <el-table-column
        label="货币单位"
        align="center"
        prop="monetaryUnitThree"
      />
      <el-table-column
        label="本期发生版税金额"
        align="center"
        prop="amountRoyaltiesIncurred"
      />
      <el-table-column
        label="本期退货版税金额"
        align="center"
        prop="returnRoyaltyAmount"
      />
      <el-table-column
        label="货币单位"
        align="center"
        prop="monetaryUnitFour"
      />
      <el-table-column
        label="累计到前已发生版税金额"
        align="center"
        prop="allAmountRoyaltiesIncurred"
      />
      <el-table-column
        label="货币单位"
        align="center"
        prop="monetaryUnitFive"
      />
      <el-table-column
        label="累计已支付版税金额(含预付款)"
        align="center"
        prop="allAmountRoyaltiesPaid"
      />
      <el-table-column label="货币单位" align="center" prop="monetaryUnitSix" />
      <el-table-column
        label="累计到前的预付款余额"
        align="center"
        prop="allDirstAdvancePayment"
      />
      <el-table-column
        label="累计带冲抵版税金额"
        align="center"
        prop="allTapeOffset"
      />
      <el-table-column
        label="货币单位"
        align="center"
        prop="monetaryUnitSeven"
      />
      <el-table-column
        label="本期因支付版税金额"
        align="center"
        prop="shouldAmountPaid"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:form:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:form:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出版社确认表对话框 -->
    <el-dialog
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :title="title"
      :visible.sync="open"
      width="600px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="220px">
        <el-form-item label="报告期间" prop="reportingPeriod">
          <el-input
            v-model="form.reportingPeriod"
            placeholder="请输入报告期间"
          />
        </el-form-item>
        <el-form-item label="卷数" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入卷数" />
        </el-form-item>
        <el-form-item label="原作品名" prop="originalTitle">
          <el-input v-model="form.originalTitle" placeholder="请输入原作品名" />
        </el-form-item>
        <el-form-item label="作品翻译书名" prop="titleEng">
          <el-input v-model="form.titleEng" placeholder="请输入作品翻译书名" />
        </el-form-item>
        <el-form-item label="权利人名" prop="obligeeName">
          <el-input v-model="form.obligeeName" placeholder="请输入权利人名" />
        </el-form-item>
        <el-form-item label="代理店名" prop="agentName">
          <el-input v-model="form.agentName" placeholder="请输入代理店名" />
        </el-form-item>
        <el-form-item label="翻译出版日" prop="translationDay">
          <el-input
            v-model="form.translationDay"
            placeholder="请输入翻译出版日"
          />
        </el-form-item>
        <el-form-item label="合同开始日" prop="commencementDate">
          <el-input
            v-model="form.commencementDate"
            placeholder="请输入合同开始日"
          />
        </el-form-item>
        <el-form-item label="合同结束日" prop="terminateDate">
          <el-input
            v-model="form.terminateDate"
            placeholder="请输入合同结束日"
          />
        </el-form-item>
        <el-form-item label="本期印刷数量" prop="printAmount">
          <el-input
            v-model="form.printAmount"
            placeholder="请输入本期印刷数量"
          />
        </el-form-item>
        <el-form-item label="本期销售数量" prop="salesAmount">
          <el-input
            v-model="form.salesAmount"
            placeholder="请输入本期销售数量"
          />
        </el-form-item>
        <el-form-item label="本期坏书·增书数量" prop="lossAmount">
          <el-input
            v-model="form.lossAmount"
            placeholder="请输入本期坏书·增书数量"
          />
        </el-form-item>
        <el-form-item label="本期末库存" prop="inventory">
          <el-input v-model="form.inventory" placeholder="请输入本期末库存" />
        </el-form-item>
        <el-form-item label="本期末累计印刷数量" prop="totalPrintAmount">
          <el-input
            v-model="form.totalPrintAmount"
            placeholder="请输入本期末累计印刷数量"
          />
        </el-form-item>
        <el-form-item label="本期末累计销售数量" prop="totalSalesAmount">
          <el-input
            v-model="form.totalSalesAmount"
            placeholder="请输入本期末累计销售数量"
          />
        </el-form-item>
        <el-form-item label="本期末累计坏书·增书数量" prop="totalLossAmount">
          <el-input
            v-model="form.totalLossAmount"
            placeholder="请输入本期末累计坏书·增书数量"
          />
        </el-form-item>
        <el-form-item label="货币单位" prop="monetaryUnitOne">
          <el-input
            v-model="form.monetaryUnitOne"
            placeholder="请输入货币单位"
          />
        </el-form-item>
        <el-form-item label="定价" prop="pricing">
          <el-input v-model="form.pricing" placeholder="请输入定价" />
        </el-form-item>
        <el-form-item label="本期版税计算数量" prop="royaltyQuantity">
          <el-input
            v-model="form.royaltyQuantity"
            placeholder="请输入本期版税计算数量"
          />
        </el-form-item>
        <el-form-item label="货币单位" prop="monetaryUnitTwo">
          <el-input
            v-model="form.monetaryUnitTwo"
            placeholder="请输入货币单位"
          />
        </el-form-item>
        <el-form-item label="本期销售/印刷金额" prop="salesAmountPrintAmount">
          <el-input
            v-model="form.salesAmountPrintAmount"
            placeholder="请输入本期销售/印刷金额"
          />
        </el-form-item>
        <el-form-item label="货币单位" prop="monetaryUnitThree">
          <el-input
            v-model="form.monetaryUnitThree"
            placeholder="请输入货币单位"
          />
        </el-form-item>
        <el-form-item label="本期发生版税金额" prop="amountRoyaltiesIncurred">
          <el-input
            v-model="form.amountRoyaltiesIncurred"
            placeholder="请输入本期发生版税金额"
          />
        </el-form-item>
        <el-form-item label="本期退货版税金额" prop="returnRoyaltyAmount">
          <el-input
            v-model="form.returnRoyaltyAmount"
            placeholder="请输入本期退货版税金额"
          />
        </el-form-item>
        <el-form-item label="货币单位" prop="monetaryUnitFour">
          <el-input
            v-model="form.monetaryUnitFour"
            placeholder="请输入货币单位"
          />
        </el-form-item>
        <el-form-item
          label="累计到前已发生版税金额"
          prop="allAmountRoyaltiesIncurred"
        >
          <el-input
            v-model="form.allAmountRoyaltiesIncurred"
            placeholder="请输入累计到前已发生版税金额"
          />
        </el-form-item>
        <el-form-item label="货币单位" prop="monetaryUnitFive">
          <el-input
            v-model="form.monetaryUnitFive"
            placeholder="请输入货币单位"
          />
        </el-form-item>
        <el-form-item
          label="累计已支付版税金额(含预付款)"
          prop="allAmountRoyaltiesPaid"
        >
          <el-input
            v-model="form.allAmountRoyaltiesPaid"
            placeholder="请输入累计已支付版税金额(含预付款)"
          />
        </el-form-item>
        <el-form-item label="货币单位" prop="monetaryUnitSix">
          <el-input
            v-model="form.monetaryUnitSix"
            placeholder="请输入货币单位"
          />
        </el-form-item>
        <el-form-item
          label="累计到前的预付款余额"
          prop="allDirstAdvancePayment"
        >
          <el-input
            v-model="form.allDirstAdvancePayment"
            placeholder="请输入累计到前的预付款余额"
          />
        </el-form-item>
        <el-form-item label="累计带冲抵版税金额" prop="allTapeOffset">
          <el-input
            v-model="form.allTapeOffset"
            placeholder="请输入累计带冲抵版税金额"
          />
        </el-form-item>
        <el-form-item label="货币单位" prop="monetaryUnitSeven">
          <el-input
            v-model="form.monetaryUnitSeven"
            placeholder="请输入货币单位"
          />
        </el-form-item>
        <el-form-item label="本期因支付版税金额" prop="shouldAmountPaid">
          <el-input
            v-model="form.shouldAmountPaid"
            placeholder="请输入本期因支付版税金额"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listForm,
  getForm,
  delForm,
  addForm,
  updateForm,
} from "@/api/system/form";

export default {
  name: "Form",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出版社确认表表格数据
      formList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportingPeriod: null,
        originalTitle: null,
        titleEng: null,
        obligeeName: null,
        agentName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        reportingPeriod: [
          { required: true, message: "报告期间不能为空", trigger: "blur" },
        ],
        volume: [{ required: true, message: "卷数不能为空", trigger: "blur" }],
        originalTitle: [
          { required: true, message: "原作品名不能为空", trigger: "blur" },
        ],
        titleEng: [
          { required: true, message: "作品翻译书名不能为空", trigger: "blur" },
        ],
        obligeeName: [
          { required: true, message: "权利人名不能为空", trigger: "blur" },
        ],
        agentName: [
          { required: true, message: "代理店名不能为空", trigger: "blur" },
        ],
        translationDay: [
          { required: true, message: "翻译出版日不能为空", trigger: "blur" },
        ],
        commencementDate: [
          { required: true, message: "合同开始日不能为空", trigger: "blur" },
        ],
        terminateDate: [
          { required: true, message: "合同结束日不能为空", trigger: "blur" },
        ],
        printAmount: [
          { required: true, message: "本期印刷数量不能为空", trigger: "blur" },
        ],
        salesAmount: [
          { required: true, message: "本期销售数量不能为空", trigger: "blur" },
        ],
        lossAmount: [
          {
            required: true,
            message: "本期坏书·增书数量不能为空",
            trigger: "blur",
          },
        ],
        inventory: [
          { required: true, message: "本期末库存不能为空", trigger: "blur" },
        ],
        totalPrintAmount: [
          {
            required: true,
            message: "本期末累计印刷数量不能为空",
            trigger: "blur",
          },
        ],
        totalSalesAmount: [
          {
            required: true,
            message: "本期末累计销售数量不能为空",
            trigger: "blur",
          },
        ],
        totalLossAmount: [
          {
            required: true,
            message: "本期末累计坏书·增书数量不能为空",
            trigger: "blur",
          },
        ],
        monetaryUnitOne: [
          { required: true, message: "货币单位不能为空", trigger: "blur" },
        ],
        pricing: [{ required: true, message: "定价不能为空", trigger: "blur" }],
        royaltyQuantity: [
          {
            required: true,
            message: "本期版税计算数量不能为空",
            trigger: "blur",
          },
        ],
        monetaryUnitTwo: [
          { required: true, message: "货币单位不能为空", trigger: "blur" },
        ],
        salesAmountPrintAmount: [
          {
            required: true,
            message: "本期销售/印刷金额不能为空",
            trigger: "blur",
          },
        ],
        monetaryUnitThree: [
          { required: true, message: "货币单位不能为空", trigger: "blur" },
        ],
        amountRoyaltiesIncurred: [
          {
            required: true,
            message: "本期发生版税金额不能为空",
            trigger: "blur",
          },
        ],
        returnRoyaltyAmount: [
          {
            required: true,
            message: "本期退货版税金额不能为空",
            trigger: "blur",
          },
        ],
        monetaryUnitFour: [
          { required: true, message: "货币单位不能为空", trigger: "blur" },
        ],
        allAmountRoyaltiesIncurred: [
          {
            required: true,
            message: "累计到前已发生版税金额不能为空",
            trigger: "blur",
          },
        ],
        monetaryUnitFive: [
          { required: true, message: "货币单位不能为空", trigger: "blur" },
        ],
        allAmountRoyaltiesPaid: [
          {
            required: true,
            message: "累计已支付版税金额(含预付款)不能为空",
            trigger: "blur",
          },
        ],
        monetaryUnitSix: [
          { required: true, message: "货币单位不能为空", trigger: "blur" },
        ],
        allDirstAdvancePayment: [
          {
            required: true,
            message: "累计到前的预付款余额不能为空",
            trigger: "blur",
          },
        ],
        allTapeOffset: [
          {
            required: true,
            message: "累计带冲抵版税金额不能为空",
            trigger: "blur",
          },
        ],
        monetaryUnitSeven: [
          { required: true, message: "货币单位不能为空", trigger: "blur" },
        ],
        shouldAmountPaid: [
          {
            required: true,
            message: "本期因支付版税金额不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询出版社确认表列表 */
    getList() {
      this.loading = true;
      listForm(this.queryParams).then((response) => {
        this.formList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        reportingPeriod: null,
        volume: null,
        originalTitle: null,
        titleEng: null,
        obligeeName: null,
        agentName: null,
        translationDay: null,
        commencementDate: null,
        terminateDate: null,
        printAmount: null,
        salesAmount: null,
        lossAmount: null,
        inventory: null,
        totalPrintAmount: null,
        totalSalesAmount: null,
        totalLossAmount: null,
        monetaryUnitOne: null,
        pricing: null,
        royaltyQuantity: null,
        monetaryUnitTwo: null,
        salesAmountPrintAmount: null,
        monetaryUnitThree: null,
        amountRoyaltiesIncurred: null,
        returnRoyaltyAmount: null,
        monetaryUnitFour: null,
        allAmountRoyaltiesIncurred: null,
        monetaryUnitFive: null,
        allAmountRoyaltiesPaid: null,
        monetaryUnitSix: null,
        allDirstAdvancePayment: null,
        allTapeOffset: null,
        monetaryUnitSeven: null,
        shouldAmountPaid: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加出版社确认表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getForm(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改出版社确认表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateForm(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addForm(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除出版社确认表编号为"' + ids + '"的数据项？')
        .then(function () {
          return delForm(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/form/export",
        {
          ...this.queryParams,
        },
        `form_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
